<?php
/**
 * 数据库配置文件
 * 州弟医院信息系统 - 州弟学安全
 */

// 数据库连接信息
define('DB_HOST', 'localhost');
define('DB_USER', 'admin');            
define('DB_PASS', 'zhoudi123');       
define('DB_NAME', 'hospital_db');     

// 创建数据库连接
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);

// 检查连接
if ($conn->connect_error) {
    die("数据库连接失败: " . $conn->connect_error);
}

// 设置字符集
$conn->set_charset("utf8mb4");

// 网站基本信息
define('SITE_NAME', '州弟医院管理系统');
define('SITE_URL', 'http://' . $_SERVER['HTTP_HOST'] . '/');
define('ADMIN_EMAIL', 'admin@zhoudihealth.com');

// 系统信息
define('VERSION', '1.0.0');
define('COPYRIGHT', '州弟学安全');

// 会话设置
ini_set('session.cookie_httponly', 1);
session_start();

// 错误报告设置
error_reporting(E_ALL);
ini_set('display_errors', 1);

// 时区设置
date_default_timezone_set('Asia/Shanghai');

// 系统日志函数
function logAction($userId, $action, $ip = null) {
    global $conn;
    
    if ($ip === null) {
        $ip = $_SERVER['REMOTE_ADDR'];
    }
    
    $userAgent = $_SERVER['HTTP_USER_AGENT'];
    
    $userId = $userId ? (int)$userId : "NULL";
    $action = $conn->real_escape_string($action);
    $ip = $conn->real_escape_string($ip);
    $userAgent = $conn->real_escape_string($userAgent);
    
    $sql = "INSERT INTO system_logs (user_id, action, ip_address, user_agent) 
            VALUES ($userId, '$action', '$ip', '$userAgent')";
    
    $conn->query($sql);
}
?> 